import request from "../request";
import type { Response } from "../types";

const getRecommendFriend: Response<
  Record<string, never>,
  {
    id: number;
    userName: string;
    userAvatar: string;
  }[]
> = params => {
  return request.post("/friends/recommend", params);
};

const makeFriends: Response<
  {
    id1: number;
    id2: number;
    userName: string;
    userAvatar: string;
  } & { commentInfo: string },
  Record<string, never>
> = params => {
  return request.post("/friends/addfriend", params);
};

const getApplyFriends: Response<
  Record<string, never>,
  {
    id: number;
    commentInfo: string;
    userAvatar: string;
    userName: string;
  }[]
> = params => {
  return request({
    method: "GET",
    url: "/friends/applyfriends",
    params: params
  });
};
const serchUser: Response<
  {
    keyword: string;
  },
  {
    id: number;
    userName: string;
    userAvatar: string;
    isConfirm: boolean;
  }[]
> = params => {
  return request.post("/user/serchuser", params);
};

const rejectFriend: Response<
  {
    userId: number;
    friendUserId: number;
  },
  Record<string, never>
> = params => {
  return request.post("/friends/rejectfriends", params);
};
const comfirmFriends: Response<
  { userId: number; friendUserId: number; commendName: string },
  Record<string, never>
> = params => {
  return request.post("/friends/confirm", params);
};
const getFriendList: Response<
  {
    userId: number;
  },
  {
    commendName: string;
    id: number;
    userAvatar: string;
    userMail: string;
    userName: string;
    userSex: string;
    userSignature: string;
  }[]
> = params => {
  return request.get("/friends/friendslist", {
    params: params
  });
};

const getFriendDetil: Response<
  { userId: number; friendUserId: number },
  {
    commendName: string;
    id: number;
    userAvatar: string;
    userMail: string;
    userName: string;
    userSex: string;
    userSignature: string;
  }
> = params => {
  return request.get("/friends/detil", {
    params: params
  });
};
const getFriend: Response<
  { userId: number; messageId: number },
  {
    commendName: string;
    id: number;
    userAvatar: string;
    userMail: string;
    userName: string;
    userSex: string;
    userSignature: string;
  }
> = params => {
  return request.post("/friends/friendUserdetil", params);
};

const changeFriendCommend: Response<
  {
    commendName: string;
    userId: number;
    friendUserId: number;
  },
  Record<string, never>
> = params => {
  return request.post("/friends/changecommend", params);
};

const deleteFriends: Response<
  {
    userId: number;
    friendUserId: number;
  },
  Record<string, never>
> = params => {
  return request.post("/friends/delete", params);
};

const getFriendlist: Response<
  {
    userId: number;
    searchvalue: string;
  },
  {
    id: number;
    commendName: string;
    userName: string;
    userAvatar: string;
  }[]
> = params => {
  return request.post("/friends/getlist", params);
};

const createdGroup: Response<
  {
    userList: Array<{
      id: number;
      name: string;
      avatar: string;
    }>;
    userName: string;
    groupCreatorId: number;
  },
  Record<string, never>
> = params => {
  return request.post("/group/creategroup", params);
};

export {
  getRecommendFriend,
  makeFriends,
  getApplyFriends,
  serchUser,
  rejectFriend,
  comfirmFriends,
  getFriendList,
  getFriendDetil,
  changeFriendCommend,
  deleteFriends,
  getFriendlist,
  createdGroup,
  getFriend
};
